﻿// CustomSizeDialog.xaml.cs
using System.Windows;
using System.Windows.Input;
using System.Linq;

namespace MainUI
{
    public partial class CustomSizeDialog : Window
    {
        public int Width { get; private set; }
        public int Height { get; private set; }

        public CustomSizeDialog()
        {
            InitializeComponent();
        }

        private void OK_Click(object sender, RoutedEventArgs e)
        {
            if (int.TryParse(WidthBox.Text, out int w) &&
                int.TryParse(HeightBox.Text, out int h) &&
                w > 0 && h > 0)
            {
                Width = w;
                Height = h;
                DialogResult = true;
                Close();
            }
            else
            {
                MessageBox.Show("请输入有效的正整数", "错误",
                    MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        // 输入验证：只允许数字
        private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
        {
            e.Handled = !e.Text.All(char.IsDigit);
        }
    }
}